<!-- from 7 5 2 7 1 8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('reportQuery.payStatus')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select :placeholder="$t('reportQuery.selectCustomer')" v-model="queryParam.search.status"
                    :dropdownMatchSelectWidth="false" showSearch allow-clear optionFilterProp="children">
                    <a-select-option v-for="item in [{id: 0, text: $t('reportQuery.unpaid')},{id: 1, text: $t('reportQuery.paid')}]" :key="item.id" :value="item.id">
                      {{ item.text }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('reportQuery.documentDate')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width: 100%"
                    v-model="queryParam.search.createTimeRange"
                    :default-value="defaultTimeStr"
                    format="YYYY-MM-DD"
                    :placeholder="[$t('reportQuery.startTime'), $t('reportQuery.endTime')]"
                    @change="onDateChange"
                  />
                </a-form-item>
              </a-col>
              
              <a-col :md="6" :sm="24" >
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons table-operator">
                  <a-button type="primary" @click="searchQuery">{{$t('reportQuery.query')}}</a-button>
                  <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="reportPrint" icon="printer">{{$t('reportQuery.print')}}</a-button>

                  <ColumnsSetting style="ma" @columnsChange="columnsChange" :columns="columns"></ColumnsSetting>
                  <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="generatePrintData" icon="printer">{{$t('inPrint.other') + $t('reportQuery.print')}}</a-button>
                  <a-button v-if="btnEnableList.indexOf(3) > -1" :loading="downLoading" style="margin-left: 8px" @click="exportExcel" icon="download">{{$t('reportQuery.export')}}</a-button>
                  <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? $t('reportQuery.putAway'): $t('reportQuery.open') }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                  </a> -->
                </span>
              </a-col>
     
            </a-row>
          </a-form>
        </div>
        <!-- table区域-begin -->
        <section ref="print" id="reportPrint">
          <a-table
            bordered
            ref="table"
            size="middle"
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="false"
            :scroll="scroll"
            :loading="loading"
            @change="handleTableChange">
            <template slot="orderNumber" slot-scope="text, record">
              <a @click="myHandleDetail(record,text, 'number')">{{text}}</a>
            </template>
            <template slot="billNumber" slot-scope="text, record">
              <a @click="myHandleDetail(record,text, 'billNo')">{{text}}</a>
            </template>
          </a-table>
          <a-row :gutter="24" style="margin-top: 8px;text-align:right;">
            <a-col :md="24" :sm="24">
              <a-pagination @change="paginationChange" @showSizeChange="paginationShowSizeChange"
                size="small"
                show-size-changer
                :showQuickJumper="true"
                :current="ipagination.current"
                :page-size="ipagination.pageSize"
                :page-size-options="ipagination.pageSizeOptions"
                :total="ipagination.total"
                :show-total="(total, range) => $t('reportQuery.common') +`${total-Math.ceil(total/ipagination.pageSize)}`+ $t('reportQuery.strip')">
                <template slot="buildOptionText" slot-scope="props">
                  <span>{{ props.value-1 }}{{$t('reportQuery.strip')}}/{{$t('reportQuery.page')}}</span>
                </template>
              </a-pagination>
            </a-col>
          </a-row>
        </section>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <component :is="detailType === 'billNo' ? 'FinancialDetail' : 'BillDetail'" ref="modalDetail" />
      </a-card>
    </a-col>
    <saleOutRepotModual ref="saleOutRepotModual" :list="dataSource" :columns="columns" :queryParam="queryParam"></saleOutRepotModual>
  </a-row>
</template>
<script>
  import BillDetail from '../bill/dialog/BillDetail'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
  import {getAction} from '@/api/manage'
  import {findBySelectSup} from '@/api/api'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import FinancialDetail from '@/views/financial/dialog/FinancialDetail'
  import moment from 'moment'
  import saleOutRepotModual from './modules/saleOutRepotModual';
  export default {
    name: "FreightPaymentReport",
    mixins:[JeecgListMixin],
    components: {
      BillDetail,
      JEllipsis,
      FinancialDetail,saleOutRepotModual
    },
    data () {
      return {
        detailType: '',
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        // 查询条件
        queryParam: {
          search: {
            organId: '',
            accountId: '',
            beginTime: getNowFormatYear() + '-01-01',
            endTime: moment().format('YYYY-MM-DD'),
            status: 0
          },
          type: '运费结算查询',
        },
        ipagination:{
          pageSize: 11,
          pageSizeOptions: ['11', '21', '31', '101', '201']
        },
        dateFormat: 'YYYY-MM-DD',
        downLoading:false,//导出按钮loading
        currentDay: moment().format('YYYY-MM-DD'),
        defaultTimeStr: '',
        supList: [],
        depotList: [],
        tabKey: "1",
        // 表头
        columns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'3%',align: 'center',customRender: (t,r,index) => parseInt(index)+1
          },
          {title:this.$t('reportQuery.documentDate'), dataIndex: 'billTimeStr', width: 80},
          {title:this.$t('reportQuery.supplier'), dataIndex: 'supplier', width: 60},
          {
            title:this.$t('reportQuery.CustomerOrderNumber'),dataIndex: 'number',width: 80,
            scopedSlots: {
              customRender: 'orderNumber'
            }
          },
          {title:this.$t('reportQuery.acceptanceWarehouse'), dataIndex: 'name', width: 80},
          {title:this.$t('reportQuery.taxInvoiceNo'), dataIndex: 'taxInvoiceNo', width: 80},
          {title:this.$t('reportQuery.transportNumber'), dataIndex: 'billNo', width: 80,
            scopedSlots: {
              customRender: 'billNumber'
            }
          },
          {title:this.$t('reportQuery.amount'), dataIndex: 'totalPrice', width: 60},
          {title:this.$t('reportQuery.PaidAmount'), dataIndex: 'paid', width: 40},
          {title:this.$t('reportQuery.UnpaidAmount'), dataIndex: 'unpaid', width: 40},
          {title:this.$t('reportQuery.Remark'), dataIndex: 'remake', width: 80},
        ],
        url: {
          list: "/accountHead/freight",
          detailList: '/depotItem/getDetailList'
        }
      }
    },
    created () {
      this.getDepotData()
      this.initSupplier()
      this.defaultTimeStr = [moment(getNowFormatYear() + '-01-01', this.dateFormat), moment(this.currentDay, this.dateFormat)]
    },
    methods: {
      moment,
      getQueryParams() {
        let param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.currentPage = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize-1;
        return param;
      },
      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.search.beginTime=dateString[0];
        this.queryParam.search.endTime=dateString[1];
      },
      initSupplier() {
        let that = this;
        findBySelectSup({}).then((res)=>{
          if(res) {
            that.supList = res;
          }
        });
      },
      getDepotData() {
        getAction('/depot/findDepotByCurrentUser').then((res)=>{
          if(res.code === 200){
            this.depotList = res.data;
          }else{
            this.$message.info(res.data);
          }
        })
      },
      myHandleDetail(record, text, type) {
        this.detailType = type
        const data = {
          billNo: {url: '/accountHead/getDetailByNumber', title: this.$t('reportQuery.transportionDocumentNoDetail')},
          number: {url: '/depotHead/getDetailByNumber', title: this.$t('manuManagement.purchaseOrder')}
        }
        if (!Object.keys(data).includes(type)) return
        getAction(data[type].url, { [type]: text }).then((res) => {
          if (res && res.code === 200) {
            this.handleDetail(res.data, data[type].title);
          }
        })
      },
      searchQuery() {
        if(this.queryParam.search.beginTime == '' || this.queryParam.search.endTime == ''){
          this.$message.warning(this.$t('reportQuery.pleaseDate'))
        } else {
          this.loadData(1);
        }
      },
        
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>